package cn.liuhuan1.blogsModel.controller;


import cn.liuhuan1.entity.PageResult;
import cn.liuhuan1.entity.ReturnResult;
import cn.liuhuan1.webModelBean.api.LeaveWordImp;
import cn.liuhuan1.webModelBean.bo.ArticleBo;
import cn.liuhuan1.webModelBean.bo.LeaveWordBo;
import cn.liuhuan1.webModelBean.vo.ArticleVo;
import cn.liuhuan1.webModelBean.vo.LeaveWordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Controller层 → 第一步 ：需要根据请求路径 找到 指定执行方法，去执行指定服务
 */

@Controller
@RequestMapping("/leaveWord")
public class LeaveWordController {
    @Autowired
    private LeaveWordImp leaveWordImp;

    @RequestMapping(value = "/getLeaveWord",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult getLeaveWord(){
        List<LeaveWordVo> getLeaveWord = leaveWordImp.getLeaveWord();
        return ReturnResult.succes(getLeaveWord);
    }
    ////////////////////////
    @RequestMapping(value = "/getPageLeaveWord",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult getPageLeaveWord(@RequestBody LeaveWordBo leaveWordBo){
        PageResult<LeaveWordVo> pageResult =  leaveWordImp.getPageLeaveWord(leaveWordBo);
        return ReturnResult.succes(pageResult);
    }

    @RequestMapping(value = "/getLeaveWordById",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult getLeaveWordById(@RequestParam("id") String id){
        LeaveWordVo leaveWordVo = leaveWordImp.getLeaveWordById(id);
        return ReturnResult.succes(leaveWordVo);
    }

    @RequestMapping(value = "/saveLeaveWord",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult saveLeaveWord(@RequestBody LeaveWordBo leaveWordBo){
        leaveWordImp.saveLeaveWord(leaveWordBo);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/updateLeaveWord", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult updateLeaveWord(@RequestBody LeaveWordBo leaveWordBo){
        leaveWordImp.updateLeaveWord(leaveWordBo);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/delLeaveWord",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult delLeaveWord(@RequestParam("id") String id){
        leaveWordImp.delLeaveWord(id);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult updateStatus(@RequestParam("id") String id,
                                     @RequestParam("status") String status){
        leaveWordImp.updateStatus(status, id);
        return ReturnResult.succes();
    }


}
